<?php

class User extends Base_Model {

    function __construct()
    {
        parent::Model();
        parent::__construct();
        $this->init("user","id_user");
    }
	
    function is_exists($email,$password)
    {
		$this->db->select("email,password")
				 ->from("user")
			 ->where("email","$email")
			 ->where("password",md5($password));
		
		$rec = $this->db->get();
		if($rec->num_rows()>0)
		{
				return TRUE;
		}
			
		return FALSE;
    }

    function update_password($id_user,$password)
    {
    	$data = array("password"=>md5($password));
    	$where = array("id_user"=>$id_user);
    	$this->update($data, $id_user);
    	
    }
    
	function get_user($email,$password)
	{
		$this->db->select("id_user,email,password,id_role")
				 ->from("user")
			 ->where("email","$email")
			 ->where("password",md5($password));
		$rec = $this->db->get();
		if($rec->num_rows()>0)
		{
			$result = $rec->result();
			return $result[0];
		}
			
		return FALSE;	
	}
	
    function add($password,$email="")
    {
            $data = array("password"=>md5($password),
						  "email"=>$email
                	  );
					  
            $this->save($data);
    }
	
}

/* End of file user.php */